#!/usr/bin/env python
# encoding: utf-8
"""
@author: youfeng
@email: youfeng243@163.com
@license: Apache Licence
@file: del_gsxt_key.py
@time: 2018/1/31 11:15
"""
import sys

import click

sys.path.append('..')

# 抓取记录缓存初始化
from cache.record_cache import RecordCache
from config.redis_conf import GS_RECORD_CACHE_CONF

# 日志模块
from logger import Logger

log = Logger('del_gsxt_key.log').get_logger()

record_cache_redis = RecordCache(GS_RECORD_CACHE_CONF['host'],
                                 GS_RECORD_CACHE_CONF['port'],
                                 GS_RECORD_CACHE_CONF['password'],
                                 GS_RECORD_CACHE_CONF['db'],
                                 GS_RECORD_CACHE_CONF['max_connections'], log=log)


@click.command()
@click.option('--province',
              default='guangdong',
              help='省份信息')
@click.option('--company',
              default='广东国立科技股份有限公司',
              help='企业信息')
def main(province, company):
    redis_key = record_cache_redis.get_gs_cache_key(province, company)
    if record_cache_redis.get(redis_key) is None:
        log.warn("当前key不存在: key = {}".format(redis_key))
        return

    record_cache_redis.delete(redis_key)
    log.info("删除key成功: key = {}".format(redis_key))


if __name__ == '__main__':
    main()
